package com.example.mvndemo.controller;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
public class GreetingController {
    @Resource
    private SimpMessagingTemplate simpMessagingTemplate;
    @RequestMapping("/helloSocket")
    public String helloSocket(){
        return "/hello/index";    
    }
    @RequestMapping("/receive")
    public String receive(){
        return "/hello/receive";
    }
    /**
     *
     * @description  这个方法是接收客户端发送功公告的WebSocket请求
     * @author liyhu
     * @date 2018/11/28 14:54
     * @return void
     **/
    @MessageMapping("/change-notice")
    public void greeting(String value){
        System.out.println("value:"+value);
        this.simpMessagingTemplate.convertAndSend("/topic/notice", value);
    }

}
